<!--安排工廠-->
            <div class="modal fade" id="tm_add_file" tabindex="-1" role="dialog" aria-labelledby="businessFileModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								&times;
							</button>
							<h4 class="modal-title" id="businessFileModalLabel">
								上传推码表
							</h4>
						</div>
						<div class="modal-body">
						<form id="tm_add_form" enctype="multipart/form-data">
						<div class="row">
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                            <input type="file" name="file" class="form-control"  />
                                        </div>
                                        </div><!-- /.col-lg-6 -->
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <button onclick="uploadTM();" type="button" class="btn btn-primary">上传</button>
                                            </div><!-- /input-group -->
                                        </div><!-- /.col-lg-6 -->
                                    </div>
						
							
			            </form>
			            <table class="table table-bordered" id="_rowdata">
                                        <tr >
                                            <th style="width: 60px">序号</th>
                                            <th>文件名</th>
                                            <th>上传时间</th>
                                            <th style="width: 60px">操作</th>
                                        </tr>
                                       
                                        </table>	
						</div>
						<div class="modal-footer">
							<button type="button" onclick="saveTM()" class="btn btn-primary" data-dismiss="modal">
								确定
							</button>
							<button type="button" class="btn btn-default" data-dismiss="modal">
								取消
							</button>
						</div>
					</div><!-- /.modal-content -->
				</div><!-- /.modal -->
			</div>
			  <script type="text/javascript">
        function addTmFile(productionPatternId){
        	
        	$("#productionPatternId").val(productionPatternId);
        	
        	_load_(productionPatternId,'scm_production_pattern-tm-file');
        	$('#tm_add_file').modal({
    			keyboard: true
    		});
        }
        function saveTM(){
        	if(confirm("确定提交流程?")){
        		$.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "../productionpattern/saveTM",
                    data:{businessId:businessId,category:category},
                    
                    success : function(map) {  
                    	if(map.head.respCode=="0000000"){
                    		alert("提交成功")
    	                }else{
    	                	alert(map.body);
    	                }
    	            },  
    	            error : function(map) {  
    	                alert("出现错误，请刷新页面");  
    	            }  

                });
        	}
        	
        }
        function _load_(businessId,category){
        	$.ajax({
                type: "POST",
                dataType: "json",
                url: "../businessfile/selectlist",
                data:{id:$("#productionPatternId").val()},
                
                success : function(map) {  
                	if(map.head.respCode=="0000000"){
                		var trObjs = $("#_rowdata tr");
                		if(trObjs.length>1){
                			for(var i =1;i<trObjs.length;i++){
                				trObjs[i].remove();
                			}
                			
                		}
	                	for(var i =0;i<map.body.length;i++){
	                		var data = map.body[i];
	                		$("#_rowdata").append("<tr><td>"+(i+1)+"</td><td>"+data.originName+"</td><td>"+data.createdAt+"</td><td><i title='下载' class='fa fa-fw fa-download'></i><i title='删除' class='fa fa-fw fa-minus-circle'></i></td></tr>");
	                	}
	                }else{
	                	alert(map.body);
	                }
	            },  
	            error : function(map) {  
	                alert("出现错误，请刷新页面");  
	            }  

            });
        }
        function uploadTM(){
        	$("#tm_add_form").ajaxSubmit({
                type: "POST",
                dataType: "json",
                url: "../businessfile/insert",
                data:{businessId:$("#productionPatternId").val(),category:'scm_production_pattern-tm-file',flag:0},
                
                success : function(map) {  
                	if(map.head.respCode=="0000000"){
	                	alert("保存成功");
	                	_load_($("#productionPatternId").val(),'scm_production_pattern-tm-file')
	                }else{
	                	alert("LL"+map.body);
	                }
	            },  
	            error : function(map) {  
	                alert("出现错误，请刷新页面");  
	            }  

            });
        }
        
        </script>